package com.kobe.tools.hystrix;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @author ：caopengfei
 * @date ：2020/12/2
 */
public class Main {

    public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {

        //每个Command对象只能调用一次,不可以重复调用,
        //重复调用对应异常信息:This instance can only be executed once. Please instantiate a new instance.
        for(int i = 0 ; i< 100 ;i++){
            final int index = i;
            Thread.sleep(200);
            new Thread() {
                @Override
                public void run() {
                    long start = System.currentTimeMillis();
                    HttpClientHystrixCommand command = new HttpClientHystrixCommand(null,"123123asdasd",index);
                    String result = command.execute();
                    System.out.println("线程"+index+"  执行时间："+(System.currentTimeMillis()-start)+" 执行结果: "+result);
                };
            }.start();

        }

        Thread.sleep(31000);
        for(int i = 0 ; i< 10 ;i++){
            final int index = i;
            long start = System.currentTimeMillis();
            HttpClientHystrixCommand command = new HttpClientHystrixCommand(null,"123123asdasd",10);
            String result = command.execute();
            System.out.println("线程"+index+"  执行时间："+(System.currentTimeMillis()-start)+" 执行结果: "+result);
        }
    }
}
